﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.StopZero.CApStopZeroBaseValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.StopZero;

public abstract class CApStopZeroBaseValidator : ITxValidator
{
  public ITxObject GetObject(string str)
  {
    if (string.IsNullOrEmpty(str))
      return (ITxObject) null;
    TxObjectList objectsByName = TxApplication.ActiveDocument.GetObjectsByName(str);
    if (objectsByName == null || ((Collection<ITxObject>) objectsByName).Count == 0)
      return (ITxObject) null;
    string errorMessage = (string) null;
    foreach (ITxObject itxObject in (Collection<ITxObject>) objectsByName)
    {
      if (this.IsValidObject(itxObject, out errorMessage))
        return itxObject;
    }
    return (ITxObject) null;
  }

  public string GetText(ITxObject obj) => obj != null ? obj.Name : string.Empty;

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    errorMessage = this.GetValidationError(obj);
    return errorMessage == null;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    return this.IsValidObject(this.GetObject(text), out errorMessage);
  }

  protected abstract string GetValidationError(ITxObject obj);
}
